package com.xinruke.hostels.reservation.controller;

import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.reservation.interfaces.dto.*;
import com.xinruke.hostels.reservation.service.DiscountsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author GuoZheng
 * @ClassName DiscountsController
 * @date：2019/7/3
 * @version: V1.0.0
 * @description：优惠管理
 */
@RestController
@RequestMapping("/discounts")
@Api(tags = "优惠管理")
public class DiscountsController extends BaseController {
    @Resource
    private DiscountsService discountsService;

    /**
     * 1.查询会员剩余可优惠次数
     *  1.1通过联系人或会员的证件号查询该人指定日期的优惠次数剩余
     *  1.2优惠次数减去预订中次数
     * 2.如果该人员在指定时间段没有优惠次数，则添加
     * @return
     */
    @PostMapping("/remaining")
    @ApiOperation("查询人员剩余可优惠次数")
    public ResultVO<Integer> remaining(@Valid @RequestBody DiscountsRemainingQueryDTO params) {

        return discountsService.queryRemainingDiscount(params);
    }

    @PostMapping("/remaining/zhengjianhao")
    @ApiOperation("根据身份信息查询剩余优惠次数")
    public ResultVO<Integer> remainingByZhengjianhao(@Valid @RequestBody DiscountsRemainingByIdentityQueryDTO params){
        return discountsService.queryRemainingDiscountByIdentity(params);
    }

    /**
     * 是否可以优惠
     * @return
     */
    @PostMapping("/if")
    @ApiOperation("查询人员是否可以优惠")
    public ResultVO<DiscountsIfCanQueryResultDTO> ifCanDiscounts(@Valid @RequestBody DiscountsIfCanQueryDTO params) {

        return discountsService.queryDiscountsPrice(params);
    }

    /**
     * 1.查询人员优惠记录
     *  1.1通过联系人或会员的证件号查询该人的优惠记录，展示关联订单信息，时间
     * @return
     */
    @PostMapping("/record")
    @ApiOperation("查询人员优惠记录")
    public ResultVO<RowsDataVO<DiscountsRecordQueryResultDTO>> record(@Valid @RequestBody DiscountsRecordQueryDTO params) {
        return null;
    }

    /**
     * 1.预订更新可优惠预订次数
     *  1.1增加指定用户预订中次数
     * @return
     */
    @PostMapping("/reservation")
    @ApiOperation("预订更新可优惠预订次数")
    public ResultVO reservation(@Valid @RequestBody List<DiscountsReservationQueryDTO> params) {
        return discountsService.reservation(params);
    }

    /**
     * 1.入住更新优惠次数
     *  1.1通过用户入住时间和预离店时间计算次数，减少优惠次数和预订中次数（入住时调用），并添加记录信息。
     * @return
     */
    @PostMapping("/check-in")
    @ApiOperation("入住更新优惠次数")
    public ResultVO checkIn(@Valid @RequestBody List<DiscountsCheckInQueryDTO> params) {
        return discountsService.checkIn(params);
    }

    /**
     * 1.提前退房补优惠
     *  1.1通过退房时间增加指定用户优惠次数（提前退房时调用）
     * @return
     */
    @PostMapping("/make-up")
    @ApiOperation("提前退房补优惠")
    public ResultVO makeUp(@Valid @RequestBody List<DiscountsMakeUpQueryDTO> params) {
        return discountsService.makeUp(params);
    }
    /**
     * 取消预订减少优惠中次数
     *
     * @return
     */
    @PostMapping("reservation/cancel")
    @ApiOperation("取消优预订")
    public ResultVO cancelReservation(@Valid @RequestBody List<DiscountsReservationQueryDTO> params) {
        return discountsService.cancelReservation(params);
    }

    /**
     * 1.新增联系人初始化优惠
     *  1.1 新增联系人用户绑定优惠接口，通过证件号判断是否需要插入数据
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增联系人初始化优惠")
    public ResultVO add(@Valid @RequestBody DiscountsAddQueryDTO params) {
        return discountsService.add(params);
    }


}
